<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>美兰数据文化馆与图书馆</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/css/public.css" media="all">
    <link rel="shortcut icon" href="<%=request.getContextPath()%>/huazhi/images/favicon.ico"/>
</head>
<style>
    /* 底部固定区域 */
    .layui-layout-admin .layui-footer {
        padding: 10px 0;
        text-align: center;
    }

    .layui-layout-admin .layui-footer {
        background-color: #fff;
    }

    .el-input__suffix {
        position: absolute;
        height: 100%;
        right: 5px;
        top: 0;
        text-align: center;
        color: #c0c4cc;
        transition: all .3s;
        pointer-events: none;
    }

</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="component-form-element">
                <div class="layui-tab-content" style="height: auto">
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <div class="layui-col-xs11">
                                <label class="layui-form-label">试剂名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" lay-verify="name"
                                           autocomplete="off" placeholder="请输入试剂名称"
                                           class="layui-input" style="padding-right: 30px;">
                                    <span class="el-input__suffix"><span class="el-input__suffix-inner"> <div
                                            class="layui-inline" lay-event="add" title="添加" style="margin-right: 5px;"> <i
                                            class="layui-icon layui-icon-add-circle-fine"
                                            style="line-height: 40px;width: 250px;"></i></div><!----><!---->
                                        <!----></span><!----></span>
                                </div>

                            </div>
                            <div class="layui-col-xs1">
                                <div class="layui-form-mid layui-word-aux"
                                     style="color: red !important;padding: 10px !important;">*
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <div class="layui-col-xs11">
                                <label class="layui-form-label">纯级</label>
                                <div class="layui-input-block">
                                    <input type="text" name="puregrade"
                                           autocomplete="off" placeholder="请输入纯级"
                                           class="layui-input">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <div class="layui-col-xs11">
                                <label class="layui-form-label">规格</label>
                                <div class="layui-input-block">
                                    <input type="text" name="norms"
                                           autocomplete="off" placeholder="请输入规格"
                                           class="layui-input">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <div class="layui-col-xs11">
                                <label class="layui-form-label">数量</label>
                                <div class="layui-input-block">
                                    <input type="text" autocomplete="off" min="0" class="layui-input"
                                           maxlength="9" oninput="value=value.replace(/[^\d\-]+/g,'')"
                                           lay-verify="quantity"   placeholder="请输入数量" name="quantity">

                                </div>
                            </div>
                            <div class="layui-col-xs1">
                                <div class="layui-form-mid layui-word-aux"
                                     style="color: red !important;padding: 10px !important;">*
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <div class="layui-col-xs11">
                                <label class="layui-form-label">用途</label>
                                <div class="layui-input-block">
                                            <textarea class="layui-textarea" name="purpose"
                                                      placeholder="请输入用途"></textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-col-lg6">
                            <div class="layui-col-xs11">
                                <label class="layui-form-label">备注</label>
                                <div class="layui-input-block">
                                            <textarea class="layui-textarea" name="remarks"
                                                      placeholder="请输入备注"></textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="batchNumber" id="batchNumber">

                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-footer" style="left: 0;padding: 0px;">
                        <button class="layui-btn" lay-submit lay-filter="*" id="pushButton">立即提交</button>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>
<script src="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/layui.all.js"></script>
<script>
    function child(batchNumber){
        layui.use(['form', 'laydate', 'layer'], function () {
            var $ = layui.$
                , form = layui.form
                , laydate = layui.laydate
                , layer = layui.layer;

            $("#batchNumber").val(batchNumber);

            //自定义验证规则
            form.verify({
                name: function (value, item) {
                    if (value == "") {
                        return '请输入试剂名称';
                    }
                },
                quantity: function (value, item) {
                    if (value == "") {
                        return '请输入数量';
                    } else {
                        var reg = /(^(0|[1-9][0-9]*|-[1-9][0-9]*)$)/;
                        if (!reg.test(value)) {
                            return '输入错误,请重新输入';
                        }
                    }
                }
            });

            //第一种方法添加用户
            form.on('submit(*)', function (data) {
                var field = data.field//当前容器的全部表单字段，名值对形式：{name: value}
                var name=field.name
                var index = layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.6});
                $("#pushButton").addClass("layui-btn layui-btn-disabled").prop("disabled", true);
                $.ajax({
                    type: "post",
                    url: "<%=request.getContextPath()%>/rest/process/addChemicalApplication",
                    data: field,
                    dataType: "json",
                    async: false,
                    success: function (obj) {
                        setTimeout(function () {
                            layer.close(index);
                            if (obj = true) {
                                layer.msg('添加成功');
                            } else {
                                layer.msg(obj.errorMsg);
                            }
                        }, 2000);
                        setTimeout(function () {
                            var indexs = parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
                            parent.layer.close(indexs);//关闭弹出层
//                        window.parent.location.reload();//刷新父页面
                        }, 4000);
                    }
                })
                return false;
            });
        });
    }
</script>
</body>
</html>